package com.tally.project.system.user.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.tally.framework.web.domain.BaseEntity;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import javax.validation.constraints.*;
import java.util.Date;

/**
 * 用户对象 sys_user
 * @author soul
 */
public class User extends BaseEntity
{
    /** 用户ID */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long userId;

    @ApiParam(name = "登录名称", value = "loginName")
    private String loginName;

    @ApiParam(name = "用户名称", value = "nickName")
    private String nickName;

    /** 用户类型 */
    @ApiParam(hidden = true)
    private String userType = "01";

    @ApiParam(name = "用户邮箱", value = "email")
    private String email;

    @ApiParam(name = "手机号码", value = "phonenumber")
    private String phonenumber;

    @ApiParam(name = "用户性别", value = "sex")
    private String sex;

    @ApiParam(name = "用户头像", value = "avatar")
    private String avatar;

    @ApiParam(name = "密码", value = "password")
    private String password;

    /** 帐号状态（0正常 1停用） */
    @ApiParam(hidden = true)
    private int status;

    /** 删除标志（0代表存在 2代表删除） */
    @ApiParam(hidden = true)
    private String delFlag;

    /** 最后登录IP */
    @ApiParam(hidden = true)
    private String loginIp;

    /** 最后登录时间 */
    private Date loginDate;

    /** 密码最后更新时间 */
    @ApiParam(hidden = true)
    private Date pwdUpdateDate;

    @ApiParam(name = "0.普通会员 1.高级会员 3.SVIP", value = "vip")
    private byte vip = 0;

    @ApiParam(name = "VIP到期时间：-1 永久", value = "vipExpire")
    private int vipExpire = -1;

    /** 默认账本ID */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long bookId = 0L;

    private String token;

    private int code;

    public User()
    {

    }

    public Long getUserId()
    {
        return userId;
    }

    public void setUserId(Long userId)
    {
        this.userId = userId;
    }


    @NotBlank(message = "登录账号不能为空")
    @Size(min = 0, max = 30, message = "登录账号长度不能超过30个字符")
    public String getLoginName()
    {
        return loginName;
    }

    public void setLoginName(String userName)
    {
        this.loginName = userName;
    }

    @Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
    public String getNickName()
    {
        return nickName;
    }

    public void setNickName(String nickName)
    {
        this.nickName = nickName;
    }

    public String getUserType()
    {
        return userType;
    }

    public void setUserType(String userType)
    {
        this.userType = userType;
    }

    @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    @Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
    public String getPhonenumber()
    {
        return phonenumber;
    }

    public void setPhonenumber(String phonenumber)
    {
        this.phonenumber = phonenumber;
    }

    public String getSex()
    {
        return sex;
    }

    public void setSex(String sex)
    {
        this.sex = sex;
    }

    public String getAvatar()
    {
        return avatar;
    }

    public void setAvatar(String avatar)
    {
        this.avatar = avatar;
    }

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    @JsonIgnore
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public byte getVip() {
        return vip;
    }

    public void setVip(byte vip) {
        this.vip = vip;
    }

    public int getVipExpire() {
        return vipExpire;
    }

    public void setVipExpire(int vipExpire) {
        this.vipExpire = vipExpire;
    }

    @JsonIgnore
    public String getDelFlag()
    {
        return delFlag;
    }

    public void setDelFlag(String delFlag)
    {
        this.delFlag = delFlag;
    }

    public String getLoginIp()
    {
        return loginIp;
    }

    public void setLoginIp(String loginIp)
    {
        this.loginIp = loginIp;
    }

    public Date getLoginDate()
    {
        return loginDate;
    }

    public void setLoginDate(Date loginDate)
    {
        this.loginDate = loginDate;
    }
    @JsonIgnore
    public Date getPwdUpdateDate()
    {
        return pwdUpdateDate;
    }

    public void setPwdUpdateDate(Date pwdUpdateDate)
    {
        this.pwdUpdateDate = pwdUpdateDate;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Long getBookId() {
        return bookId;
    }

    public void setBookId(Long bookId) {
        this.bookId = bookId;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("userId", getUserId())
            .append("nickName", getNickName())
            .append("loginName", getLoginName())
            .append("userType", getUserType())
            .append("email", getEmail())
            .append("phonenumber", getPhonenumber())
            .append("sex", getSex())
            .append("avatar", getAvatar())
            .append("password", getPassword())
            .append("status", getStatus())
            .append("vip", getVip())
            .append("vipExpire", getVipExpire())
            .append("delFlag", getDelFlag())
            .append("loginIp", getLoginIp())
            .append("loginDate", getLoginDate())
            .append("createBy", getCreateBy())
            .append("createTime", getCreateTime())
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("remark", getRemark())
            .toString();
    }
}
